package com.codeduck.test.job;

import com.codeduck.test.mapper.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @author: <a href="mailto:codeduck@163.com">codeduck</a>
 * @date: 2022/11/06
 */
@Component
@Slf4j
public class DataBackupAndCleaning {
    @Resource
    private AlarmInfoMapper alarmInfoMapper;
    @Resource
    private AlarmInfoHisMapper alarmInfoHisMapper;
    @Resource
    private TransDtlMapper transDtlMapper;
    @Resource
    private TransDtlHisMapper transDtlHisMapper;
    @Resource
    private FileInfoMapper fileInfoMapper;

    @Transactional(rollbackFor = Exception.class)
    public void transDtlDataBackupAndCleaning(String part, int start, int size) {
        transDtlHisMapper.insertBeforeDataCleaning(part, start, size);
        transDtlMapper.partitionDataCleaning(part, size);
    }
    @Transactional(rollbackFor = Exception.class)
    public void alarmInfoDataBackupAndCleaning(String part, int start, int size) {
        alarmInfoHisMapper.insertBeforeDataCleaning(part, start, size);
        if (size < 600) {
            throw new RuntimeException("数据备份与清理时发生异常");
        }
        alarmInfoMapper.partitionDataCleaning(part,size);
    }

    public void fileInfoCleaning(String part) {
        fileInfoMapper.partitionDataCleaning(part);
        log.info("文件表分区[{}]数据已清理完毕",part);
    }
}
